//
// Created by Administrator on 2024/8/9.
//

#ifndef JTT809_0X9301_H
#define JTT809_0X9301_H
#include "jtt809_sub_body.h"
#include "../../msgpack/MessagePackWriter.h"
#include "../../msgpack/messagepack_reader.h"
#include "../../util/macros.h"
#include "../../util/types.h"

namespace protocol {
    class JTT809_0x9301 final : public JTT809SubBody { public:
        uint8_t objectType{};
        char objectId[20]{};
        uint8_t answerTime{};
        uint32_t infoId{};
        uint32_t infoLength{};
        Container<char> infoContent;
        IMPLEMENT_SIZEABLE(objectType, objectId, answerTime, infoId, infoLength, infoContent)
    public:
        JTT809_0x9301() : JTT809SubBody(0x9301) {}

        JTT809_0x9301(const uint8_t object_type, const char object_id[20], const uint8_t answer_time, const uint32_t info_id,
            const Container<char> &info_content)
            : JTT809SubBody(0x9301), objectType(object_type),
              answerTime(answer_time),
              infoId(info_id),
              infoLength(size(info_content)),
              infoContent(info_content) {
            std::copy_n(object_id, sizeof(objectId), objectId);
        }

        JTT809_0x9301(const JTT809_0x9301 &other) = default;

        JTT809_0x9301 & operator=(const JTT809_0x9301 &other) = default;

        ~JTT809_0x9301() override = default;

        void serialize(MessagePackWriter &writer) override {
            writer.writeUint(objectType);
            writer.writeString(objectId);
            writer.writeByte(answerTime);
            writer.writeUint(infoId);
            writer.writeUint(infoLength);
            infoContent.serialize(writer);
        }

        void deserialize(MessagePackReader &reader) override {
            reader.readUint(objectType);
            reader.readString(objectId);
            reader.readByte(answerTime);
            reader.readUint(infoId);
            reader.readUint(infoLength);
            infoContent = Container<char>(reader, infoLength);
        }

        [[nodiscard]] std::string toString() const override { return "????????????"; }
    };
}

#endif //JTT809_0X9301_H
